﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using AccessLayer;
using ObjectLayer;

namespace BSC
{
    public partial class fact_cost_import : System.Web.UI.Page
    {
        static List<ObjectLayer.fact_costs_revenuesBO> lst;
        protected void Page_Load(object sender, EventArgs e)
        {
            //((Main)this.Page.Master).ResourceManager1.Theme = Ext.Net.Theme.Gray;
        }
        public static List<fact_costs_revenuesBO> GetAll()
        {
            return lst;
        }
        protected void refresh(object sender, StoreRefreshDataEventArgs e)
        {
            Store1.DataSource = lst;
        }
        protected void Upload(object sender, DirectEventArgs e)
        {
            if (!FileUploadField1.HasFile)
            {
                X.Msg.Show(new MessageBoxConfig
                {
                    Buttons = MessageBox.Button.OK,
                    Icon = MessageBox.Icon.ERROR,
                    Title = "Fail",
                    Message = "Vui lòng chọn file chi phí"
                });
                return;
            }
            string path = Server.MapPath(@"~/content/upload/temp/" + FileUploadField1.FileName);
            FileUploadField1.PostedFile.SaveAs(path);
            lst = new List<fact_costs_revenuesBO>();
            Import(path, e);

        }
        protected void OptimizeCode(object sender, DirectEventArgs e)
        {
            if (!FileUploadField1.HasFile)
            {
                Global.GlobalMethod.ErrorMsg("Vui lòng chọn file chi phí");
            }
            string path = Server.MapPath(@"~/content/upload/temp/" + FileUploadField1.FileName);
            FileUploadField1.PostedFile.SaveAs(path);
            RevenuesExcelReader dao = new RevenuesExcelReader();
            dao.Optimize(path, e);

        }

        private void Import(string path, DirectEventArgs e)
        {
            CostExcelReader dao = new CostExcelReader();
            dao.lst = lst;
            dao.Import(path, e);
            
        }
    }
}
